<template>
  <div class="app">
    <div class="tabbar">
      <van-icon @click="back" name="arrow-left" size="20" />
      <van-icon name="ellipsis" size="23" />
    </div>
    <div class="top">
      <div class="header">
        <img :src="item.itemimg" alt="" />
      </div>
      <div class="miaoshu">
        <div class="itemname">
          <span>{{ item.itemname }}</span>
        </div>
        <div class="sellcount">月售{{ item.itemsellnum }}</div>
        <div class="sellPrice">
          <div class="leftspan">
            <span class="span0">￥</span>
            <span class="span1">{{ item.itemprice }}</span>
          </div>
          <Cardcontrol :sellnum="item.sellcount" :count="item.itemid" />
        </div>
      </div>
    </div>
    <van-tabs class="tabs" v-model:active="active" shrink color="#FFCC4D">
      <van-tab title="详情">
        <div class="introduce">
          <span class="introduceauthor">掌柜描述:</span>
          <span class="text">{{ item.controduce }}</span>
        </div>
        <div class="content">
          <div class="header">外卖评价</div>
        </div>
      </van-tab>
      <van-tab title="评价">内容 2</van-tab>
    </van-tabs>
    <Shopcart :truefee="shopdetail.truefee"></Shopcart>
  </div>
</template>

<script>
import { useRouter, useRoute } from "vue-router";
import { computed, onMounted, reactive, toRefs, watch } from "@vue/runtime-core";
import { useStore } from "vuex";
import Shopcart from "../components/Shopcart.vue";
import Cardcontrol from "@/components/Cardcontrol";
import { setLocal } from '../common/utils';
export default {
  
  setup() {
    const store = useStore();
    const router = useRouter()
    const route = useRoute()
    const state = reactive({
      item: {},
      shopdetail: {}
    });
    onMounted(async () => {
      store.state.flag = true
      state.shopdetail = store.state.shopdetail
      let id = store.state.itemdetailid
      let p = store.state.itemlist.find(v => v.itemid === id)
      state.item = p
    });
    const back = () => {
      router.go(-1)
    }
    const getChange = computed(() => {
      return store.state
    })
    watch(getChange, () => {
      setLocal(`store${route.params.id}`, JSON.stringify(store.state));
    }, {deep:true})
    return {
      ...toRefs(state),
      getChange,
      back
    };
  },
  components: {
    Shopcart,
    Cardcontrol,
  },
};
</script>

<style lang="less" scoped>
.app {
  -webkit-overflow-scrolling: touch;
  width: 100%;
  background: #f4f4f4;
  height: 100%;
  position: fixed;
  overflow: scroll;
  .tabbar {
    font-weight: 800;
    color: black;
    align-items: center;
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding: 15px 12px;
    justify-content: space-between;
    position: fixed;
    top: 0;
  }
  .top {
    margin-bottom: 12px;
    .header {
      width: 100%;
      height: 280px;
      overflow: hidden;
      img {
        width: 100%;
      }
    }
    .miaoshu {
      box-sizing: border-box;
      padding: 15px 15px;
      display: flex;
      width: 100%;
      height: 120px;
      background: pink;
      flex-direction: column;
      justify-content: space-between;
      background: #fff;
      .itemname {
        color: #111;
        width: 100%;
        font-weight: 500;
        word-wrap: break-word;
        word-break: break-all;
        overflow: hidden;
        span {
          font-size: 20px;
          font-weight: 600;
        }
      }
      .sellcount {
        height: 18px;
        width: 100%;
        color: #a8aaaa;
        font-size: 12px;
      }
      .sellPrice {
        width: 100%;
        height: 35px;
        transform: translateX(-3px);
        display: flex;
        justify-content: space-between;
        align-items: center;
        .span0 {
          color: #fb5249;
          font-size: 14px;
          font-weight: 600;
          line-height: 35px;
        }
        .span1 {
          color: #fb5249;
          font-weight: 600;
          line-height: 35px;
          font-size: 21px;
        }
      }
    }
  }
  .tabs {
    height: 140px;
    background: #fff;
    .introduce {
      background: #fff;
      display: flex;
      box-sizing: border-box;
      padding: 15px 15px;
      .introduceauthor {
        color: #a8aaaa;
        font-size: 12px;
        flex: 1;
      }
      .text {
        font-size: 14px;
        color: #524f4d;
        font-family: inherit;
        box-sizing: border-box;
        padding-right: 8px;
        width: 270px;
        margin-left: 20px;
      }
    }
    .content {
      height: 500px;
      background: #fff;
      box-sizing: border-box;
      padding: 15px 15px;
      .header {
        font-size: 18px;
        color: #111;
        font-weight: 600;
      }
    }
  }
}
/deep/ .cart-control .cart-count {
  transform: translateY(0);
}
</style>